{$CLEO .cm}
{$USE CLEO+}


0000:
const
    MISSION_CAR = 0@
    damage_dealt = 1@ 
    Voice_clip = 2@ 
    Line_is_playing = 3@
    Line_number_played_times =4@ 
    Partice_attach_to_vehicle = 25@
    Location = 449@
end

MODEL.Load(#HUNTLEY)
MODEL.Load(#WMYBMX)
load_requested_models

//Start position

:RELOAD_MODELS
wait 0
if and
Model.Available(#HUNTLEY)
Model.Available(#WMYBMX)
jf @RELOAD_MODELS

$onmission = 2 


:cutscene_play

0707: start_scene_skip_to @Skip_cutscene 
     fade 0 1000
     wait 1000
     fade 1 1000
    actor_remove_from_car_and_put_at player1  284.5229 -7692.8882 8.1649
    actor.Angle(player1)= 268.129
    gosub @spawn_player2 
    0395: clear_area 1 at 281.0754 -7684.7461 12.8381 radius 999999999.0
 
     
80@ = actor.Create(40, #WMYBMX, 289.1259, -7692.5771, 8.1649)
actor.Angle( 80@ ) = 99.4268
060B: set_actor 80@ decision_maker_to 32
actor.LockInCurrentPosition(80@,1  ) 
0677: AS_actor  80@ chat_with_actor player1 lead_speaker_flag 0 unknown_flag 1 
0619: enable_actor 80@ collision_detection 0

015F: set_camera_position 282.9518 -7693.6021 8.1649  rotation 0.0 0.0 0.0
0160: set_camera_point_at 289.1259 -7692.5771 8.1649  switchstyle 2

   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\cut1.wav")
   audiostream.PerformAction( Voice_clip ,play )
     show_text_highpriority "Hi, fellas. I was hoping you'd stop by, I want you to go deliver those who are morons." 10000
     repeat 
     wait 0 
     0AAF: Line_is_playing = get_audiostream_length Voice_clip
     until Line_is_playing == -1  
   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\cut2.wav")
   audiostream.PerformAction( Voice_clip ,play )
     show_text_highpriority "But hey! I have the car good and all working but I have this old car for years and hardly not used." 10000
     repeat 
     wait 0 
     0AAF: Line_is_playing = get_audiostream_length Voice_clip
     until Line_is_playing == -1  
        Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\cut3.wav")
   audiostream.PerformAction( Voice_clip ,play )
     show_text_highpriority "When cars are empty, you only use my old car but now I don't really want it but you guys can have it now, good luck." 10000
     repeat 
     wait 0 
     0AAF: Line_is_playing = get_audiostream_length Voice_clip
     until Line_is_playing == -1  
     
     fade 0 1000
     wait 1000
     fade 1 1000
     actor.DestroyInstantly( 80@ )
     :Skip_cutscene 
     0701: end_scene_skip
    
    camera.Restore_WithJumpCut()
    actor_remove_from_car_and_put_at player1 283.4956 -7688.0063 7.1649
    actor.Angle(player1)=8.1538
    gosub @spawn_player2 
    //Begin the mission, with Bobby taking it's place 
    MISSION_CAR = car.Create( #HUNTLEY ,271.7083, -7685.3677, 7.8359 )
    car.Angle( MISSION_CAR )=0.6936
    car.Health( MISSION_CAR ) = 50000
    09C4: set_car MISSION_CAR gas_tank_explosion_enabled 0

    Partice_attach_to_vehicle=0
     Audiostream.Release( Voice_clip )
    018A: Location = create_checkpoint_at -979.5864 -6693.5879 7.9279
    0376: 180@ = create_random_actor_at -979.9068 -6689.8369 8.9341 
    actor.Angle(180@)= 185.6244
    actor.health(180@)= 1200
    060B: set_actor 180@ decision_maker_to 32   //prevent for actions
    0446: set_actor 180@ dismemberment_possible 0

    //Wasteland ruins
    while true 
    wait 0
       gosub @common 
       gosub @play_lines 
       if  00FE:   actor $PLAYER_ACTOR sphere 1 in_sphere  -979.5864 -6693.5879 7.9279 radius 4.0 4.0 4.0 
       then marker.Disable( Location )
       break 
       end
    end
   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\made1.wav")
   audiostream.PerformAction( Voice_clip ,play ) 
   show_text_highpriority "Did you bring it? - Alright! There's more areas to deliever, try delivering to neighbouring hoods closer to Nuketown." 10000

    018A: Location = create_checkpoint_at -804.6308 -7516.0078 7.818 
    0376: 180@ = create_random_actor_at -804.6308 -7516.0078 7.818  
    actor.Angle(180@)=  269.628
    actor.health(180@)= 1200
    06B0: AS_actor 180@ sit_down 9000000 ms
    060B: set_actor 180@ decision_maker_to 32   //prevent for actions
    0446: set_actor 180@ dismemberment_possible 0
    Line_number_played_times=0 
    
    //Nuketown 
    while true 
    wait 0
       gosub @common  
       if  00FE:   actor $PLAYER_ACTOR sphere 1 in_sphere  -801.7512 -7515.6392 7.81  radius 4.0 4.0 4.0 
       then marker.Disable( Location )
       break 
       end
    end
    
    //Quote delievered 
   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\made2.wav")
   audiostream.PerformAction( Voice_clip ,play ) 
   show_text_highpriority "Nice! Oh there's the last location called desert downtown, that city belongs to the richest people." 10000
   32@=0
   repeat
   wait 0
    0AAF: Line_is_playing = get_audiostream_length Voice_clip
     gosub @common
   until 32@ > 13000 // Line_is_playing == -1 
   
   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\made3.wav")
   audiostream.PerformAction( Voice_clip ,play ) 
   show_text_highpriority " We need to get to is the person standing by the motel. GO!" 10000

   marker.Disable(location)
    //Downtown motel  
    018A: Location = create_checkpoint_at  278.6187 -6957.269 7.9385
    0376: 180@ = create_random_actor_at  278.6187 -6957.269 7.9385
    actor.Angle(180@)=  354.3971 
    actor.health(180@)= 1200
    06B0: AS_actor 180@ sit_down 9000000 ms
    060B: set_actor 180@ decision_maker_to 32   //prevent for actions
    0446: set_actor 180@ dismemberment_possible 0    
    
    while true 
    wait 0
       gosub @common  
       if  00FE:   actor $PLAYER_ACTOR sphere 1 in_sphere  278.9038 -6950.0981 7.93  radius 5.0 5.0 5.0 
       then marker.Disable( Location )
       break 
       end
    end
   
   Audiostream.Release( Voice_clip )
   Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\made4.wav")
   audiostream.PerformAction( Voice_clip ,play ) 
   show_text_highpriority "That's it! Come to my bar and will get this shit started!" 10000
     018A: Location = create_checkpoint_at 271.0291 -7677.8325 7.8359 
     
    while true 
    wait 0
       gosub @common  
       if  00FE:   actor $PLAYER_ACTOR sphere 1 in_sphere  271.0291 -7677.8325 7.8359 radius 5.0 5.0 5.0 
       then marker.Disable( Location )
       break 
       end
    end       
    
    fade 0 1000 
    wait 1000
    fade 1 1000  
 :CLEANUP_MISSION
 $onmission = 0 
 Audiostream.Release( Voice_clip )    
 0650: destroy_particle 30@
 marker.Disable(Location)
 MISSION_CLEANUP
 END_THREAD    
 
 
 :common
 
 if cheat "exit"
 then
     show_styled_text "~r~Aborted the Job!" 3000 5 
     jump @CLEANUP_MISSION
 end
    //Car is defined for the mission, use it and don't destroy it.
    if is_car_defined MISSION_CAR
    then
        0E65: get_car_collision_intensity MISSION_CAR store_to 200@  
        0E66: get_car_collision_coordinates MISSION_CAR store_to 201@ 202@ 203@     
    
       damage_dealt=car.Health( MISSION_CAR )
       if  200@ >= 120.0
       then
           damage_dealt=car.Health( MISSION_CAR )
           damage_dealt-=5000
           car.Health( MISSION_CAR )=damage_dealt 
       end 
       if   
        damage_dealt <= 47000
       then
          081D: set_car MISSION_CAR engine_broken 1
          0918: set_car MISSION_CAR engine_operation 0
          car.SetSpeedInstantly( MISSION_CAR,0.0 )
          04FE: deflate_tire 1 on_car MISSION_CAR

          if Partice_attach_to_vehicle==0
          then
          066C: 30@ = attach_particle "overheat_car_electric" to_car MISSION_CAR with_offset 0.0 1.5 0.0 rotation 0.0 0.0 0.0 type 1
          064C: make_particle 30@ visible
          Partice_attach_to_vehicle=1
          end
          
       end 
       {
       if or 
       not 31@==0
       car.Wrecked(MISSION_CAR )
       02BF:   car MISSION_CAR sunk
       8205:  not actor $PLAYER_ACTOR near_car MISSION_CAR radius 200.0 200.0 200.0 flag 0 
       then
            0650: destroy_particle 30@
            25@=0
            car.RemoveReferences(MISSION_CAR)
             
       end      }
    end  
 return 
 :play_lines
 0AAF: Line_is_playing = get_audiostream_length Voice_clip

        if Line_is_playing == -1 
        then
            if Line_number_played_times == 0 
            then
               Audiostream.Release( Voice_clip )
               Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\Start1.wav")
               audiostream.PerformAction( Voice_clip ,play )
               Line_number_played_times += 1 
               show_text_highpriority "Okay, now you have bring the product down to the ruins, wasteland people who lives in hell when they die for food." 10000
               return 
            end 
            if Line_number_played_times == 1 
            then
               Audiostream.Release( Voice_clip )
               Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\Start2.wav")
               audiostream.PerformAction( Voice_clip ,play )
               Line_number_played_times += 1 
               show_text_highpriority "But you know what? It a food for poor people who lost theirs house and they can't buy anything." 10000
               return 
            end 
            if Line_number_played_times == 2 
            then
               Audiostream.Release( Voice_clip )
               Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\Start3.wav")
               audiostream.PerformAction( Voice_clip ,play )
               Line_number_played_times += 1 
               show_text_highpriority "You gotta help them! It's our only choice." 10000
               return 
            end 
            if Line_number_played_times == 3 
            then
               Audiostream.Release( Voice_clip )
               Voice_clip=audiostream.Load("cleo\[@railcity]\Car_deliver01\Start4.wav")
               audiostream.PerformAction( Voice_clip ,play )
               Line_number_played_times += 1 
               show_text_highpriority "I would say instead, it's a food for living but try not to eat alright? - Bobby out!" 10000
               return 
            end 
        end
 
 return 


 :spawn_player2 
 if coop
 return_if_false
  04C4: store_coords_to 40@ 41@ 42@ from_actor player1 with_offset 0.0 -1.0 -1.0
  43@=actor.Angle(player1)
  actor.Angle(player2)=43@
  actor_remove_from_car_and_put_at   player2   40@ 41@ 42@

 return 